<?php
/**
 * Created by PhpStorm.
 * User: surface
 * Date: 2019/1/11
 * Time: 20:19
 */
namespace app\Manage\controller;
use Request;

use app\common\controller\Manage as ManageController;

class StockList extends ManageController{

    public function stockList()
    {
        if (Request::isAjax()) {
            $input = input();
            $room_bn = $input['room_bn'];
            $condition = '1=1';
            if($room_bn) {
                $condition .= ' and log.room_bn like "%'.$room_bn.'%"';
            }
            if($input['goods_name']) {
                $condition .= ' and goods.name like "%'.$input['goods_name'].'%"';
            }
            $field = 'log.*, goods.name as goods_name, FROM_UNIXTIME(log.ctime, \'%Y-%m-%d %H:%i:%s\') as date';
            $list = \think\Db::name('stock_list')
                    ->alias('log')
                    ->join('goods', 'goods.id = log.goods_id', 'left')
                    ->where($condition)
                    ->field($field)
                    ->order('id desc')
                    ->paginate($input['limit']);
            $re['code'] = 0;
            $re['msg'] = '';
            $re['count'] = $list->total();
            $re['data'] = $list->items();
            return $re;
        }
        return $this->fetch('index');
    }
}